<?php

namespace app\store\model\lottery;

use think\Cache;
use app\common\model\lottery\Prize as PrizeModel;

/**
 * 抽奖奖品模型
 * Class Prize
 * @package app\store\model\lottery
 */
class Prize extends PrizeModel
{
	/**
	 * 
	 */
	public function getList()
	{
		return $this->with('image')
			->alias('active')
			->where('is_delete', '=', 0)
            ->order(['create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);
	}

	/**
	 */
	public function add($data)
	{
		if (empty($data['image_id'])) {
            $this->error = '请上传封面图';
            return false;
        }
		$data['wxapp_id'] = self::$wxapp_id;
		$data['province_id'] = self::$region['province'];
		$data['city_id'] = self::$region['city'];
		return $this->allowField(true)->save($data);
	}

	/**
	 * 
	 */
	public function edit($data)
	{
		if (empty($data['image_id'])) {
            $this->error = '请上传封面图';
            return false;
        }
		$data['wxapp_id'] = self::$wxapp_id;
		$data['province_id'] = self::$region['province'];
		$data['city_id'] = self::$region['city'];
		return $this->allowField(true)->save($data) !== false;
	}

	/**
	 * 
	 */
	public function setDelete()
	{
		return $this->save(['is_delete' => 1]);
	}
}